import JT
import numpy as np

def GetValue(params):
#    From calculation, we expect that the local minimum occurs at x=9/4
#    The algorithm starts at x=6
    
    xNew = params[0] 
    eps = 0.01
    xNew = (4*xNew*xNew*xNew-9*xNew*xNew)
    params[0] = xNew
    return params

def Optimize():
    opt = JT.Optimizer()
    opt.SetFunction(GetValue)
    opt._nParams = 1
    opt._stepSize = 0.01
    opt._tol = 0.00001
    params = np.zeros(1)
    params[0] = 6
    opt.SetInitialParameters(params)
    bestParam, bestVal = opt.Optimize()
    print "Best Parameters:" , bestParam, ", Best Value: ", bestVal
    
if __name__ == "__main__":
    Optimize()